<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class main_model extends CI_Model {

	public function get_web_service()
	{
		$query = $this->db->get('web_service');
		return $query->result_array();
	}

	public function get_slide()
	{	
		$this->db->where('vdo_status' ,0);
		$this->db->where('slide_status' ,1);
		$this->db->where('thumb_choose' ,1);
		$this->db->join('vdo_thumb','vdo_thumb.vdo_id = vdo.vdo_id','left');		
		$query = $this->db->get('vdo');
		return $query->result_array();
	}
	public function new_vdo()
	{		
		$this->db->where('vdo_status' ,0);
		$this->db->order_by("vdo.vdo_id", "desc");
		$this->db->where('vdo_thumb.thumb_choose',1);
		$this->db->join('vdo_thumb','vdo_thumb.vdo_id = vdo.vdo_id','left');
		$query = $this->db->get('vdo',4);
		return $query->result_array();
	}

	public function new_category($i)
	{
		$this->db->where('vdo.vdo_status' ,0);
		$this->db->where('vdo.category_id',$i);
		$this->db->where('vdo_thumb.thumb_choose',1);
		$this->db->join('category','category.category_id = vdo.category_id','left');
		$this->db->join('vdo_thumb','vdo_thumb.vdo_id = vdo.vdo_id','left');
		$query = $this->db->get('vdo' ,6);
		return $query->result_array();
	}

	public function get_category()
	{
		$query = $this->db->get('category');
		return $query->result_array();
	}

	public function get_member($id)
	{
		$this->db->where('mem_id',$id);
		$query = $this->db->get('member');
		return $query->result_array();
	}

	public function get_favorite($mem_id)
	{
		$this->db->where('vdo_status' ,0);
		$this->db->where('thumb_choose',1);
		$this->db->where('favorite.mem_id' ,$mem_id);
		$this->db->order_by('fav_id' , 'desc');
		$this->db->join('vdo','vdo.vdo_id = favorite.vdo_id','left');
		$this->db->join('vdo_thumb','vdo_thumb.vdo_id = favorite.vdo_id','left');
		$query = $this->db->get('favorite' ,6);
		return $query->result_array();
	}

	public function get_top_view()
	{
		$this->db->where('vdo.vdo_status' ,0);
		$this->db->where('vdo_thumb.thumb_choose',1);
		$this->db->join('category','category.category_id = vdo.category_id','left');
		$this->db->join('vdo_thumb','vdo_thumb.vdo_id = vdo.vdo_id','left');
		$this->db->order_by('vdo.vdo_view' , 'desc');
		$this->db->group_by('vdo.vdo_id');
		$query = $this->db->get('vdo' ,6);
		return $query->result_array();
	}

	public function get_top_like()
	{
		$this->db->where('vdo_status' ,0);
		$this->db->where('thumb_choose',1);
		$this->db->where('like_rate' ,1);
		$this->db->select('like.vdo_id ,vdo_name ,thumb_name ,vdo_rawfile ,vdo_uploadtime');
		$this->db->join('vdo','vdo.vdo_id = like.vdo_id','left');	
		$this->db->group_by('like.vdo_id');
		$this->db->order_by('like_rate' ,'desc');
		$this->db->join('vdo_thumb','vdo_thumb.vdo_id = like.vdo_id','left');
		$this->db->group_by('vdo_thumb.vdo_id');	
		$this->db->select_sum('like_rate');
		$query = $this->db->get('like' ,6);
        return $query->result_array();
	}
	
}